package com.gmall.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig_Direct {

    public static final String Exchange_Direct_1 = "Exchange_Direct_1";

    public static final String Queue_Direct_1 = "Queue_Direct_1";
    public static final String Queue_Direct_2 = "Queue_Direct_2";
    public static final String Queue_Direct_3 = "Queue_Direct_3";

    private static final String ROUTING_KEY_1 = "sms";
    private static final String ROUTING_KEY_2 = "email";
    private static final String ROUTING_KEY_3 = "qq";
    private static final String ROUTING_KEY_4 = "sms";

    @Bean(Exchange_Direct_1)
    public Exchange exchange_Direct_1(){
        return ExchangeBuilder.directExchange(Exchange_Direct_1).build();
    }

    @Bean(Queue_Direct_1)
    public Queue queue_Direct_1(){
        return QueueBuilder.durable(Queue_Direct_1).build();
    }

    @Bean(Queue_Direct_2)
    public Queue queue_Direct_2(){
        return QueueBuilder.durable(Queue_Direct_2).build();
    }

    @Bean(Queue_Direct_3)
    public Queue queue_Direct_3(){
        return QueueBuilder.durable(Queue_Direct_3).build();
    }

    /**
     *将Queue_Direct_1 绑定到交换机Exchange_direct  with
     * @param queue
     * @param exchange
     * @return
     */
    @Bean
    public Binding binding_direct_1(
            @Qualifier(Queue_Direct_1) Queue queue,
            @Qualifier(Exchange_Direct_1) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY_1).noargs();
    }

    @Bean
    public Binding binding_direct_2(
            @Qualifier(Queue_Direct_2) Queue queue,
            @Qualifier(Exchange_Direct_1) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY_2).noargs();
    }

    @Bean
    public Binding binding_direct_3(
            @Qualifier(Queue_Direct_3) Queue queue,
            @Qualifier(Exchange_Direct_1) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY_3).noargs();
    }

    @Bean
    public Binding binding_direct_4(
            @Qualifier(Queue_Direct_3) Queue queue,
            @Qualifier(Exchange_Direct_1) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY_4).noargs();
    }
}
